#include "stageselect.h"

StageSelect::StageSelect(QWidget *parent) : QWidget(parent)
{


    //创建关卡选择
    for(int i=0;i<20;i++){
        MyPushButton *btn_menu=new MyPushButton(":/res/LevelIcon.png");
        btn_menu->setParent(parent);
        btn_menu->move(25 + (i%4)*70 , 130+ (i/4)*70);

        //添加图片上的数字
        QLabel *label=new QLabel(btn_menu);
        //设置标签大小，才能让数字居中
        label->setFixedSize(btn_menu->width(),btn_menu->height());
        //要用QString::number()才能将int数字转化为string字符来显示
        label->setText(QString::number(i+1));
        //将文字居中
        label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        //使鼠标穿透标签，可以直接点击下一层的btn_back按钮
        label->setAttribute(Qt::WA_TransparentForMouseEvents,true);

        //监听选择关卡的信号槽
        connect(btn_menu,&MyPushButton::clicked,[=](){
            QString str=QString("点击了第%1关").arg(i+1);
            qDebug()<<str;
            if(playscene==NULL){
                parent->hide();
                playscene=new PlayScene(i+1);
                playscene->show();

                //监听关卡场景的信号
                connect(playscene,&PlayScene::choosesceneback,[=](){
                    parent->show();
                    delete playscene;
                    playscene=NULL;
                });
            }
         });
    }
    //设置鼠标穿透事件，不然会挡住菜单栏，无法点击
    this->setAttribute(Qt::WA_TransparentForMouseEvents,true);
}


